#pragma once 
#include <string>
#include <ctemplate/template.h>
#include "oj_model.hpp"

const std::string template_html_allques = "./template_html/";
const std::string template_html_oneques = "./template_html/";

class View{
public:
    View(){}
    ~View(){}

    void ExpandQuestionAll(const std::vector<struct Question>& ques, std::string* out){
        //1. 形成路径
        std::string src_html = template_html_allques + "all_ques.html";
        //2. 形成根字典
        ctemplate::TemplateDictionary root("all_questions");
        //3. 循环遍历 填充字典
        for(auto& q : ques){
            ctemplate::TemplateDictionary* sub = root.AddSectionDictionary("question_list");
            sub->SetValue("number", q._number);
            sub->SetValue("title", q._title);
            sub->SetValue("level", q._level);
        }
        //4. 获取渲染对象 DO_NOT_STRIP表示的是：不跳过任何特殊字符，保持原貌
        ctemplate::Template* tpl = ctemplate::Template::GetTemplate(src_html, ctemplate::DO_NOT_STRIP);
        //5.获取渲染结果
        tpl->Expand(out, &root);        
    }

    void ExpandQuestionOne(const struct Question& q, std::string* out){
        //1. 形成路径
        std::string src_html = template_html_allques + "one_ques.html";
        //2. 形成根字典
        ctemplate::TemplateDictionary root("one_question");
        //3.设置字典
        root.SetValue("number", q._number);
        root.SetValue("title", q._title);
        root.SetValue("level", q._level);
        root.SetValue("desc", q._desc);
        root.SetValue("pre_code", q._header);
        //4. 获取渲染对象 DO_NOT_STRIP表示的是：不跳过任何特殊字符，保持原貌
        ctemplate::Template* tpl = ctemplate::Template::GetTemplate(src_html, ctemplate::DO_NOT_STRIP);
        //5.获取渲染结果
        tpl->Expand(out, &root);
    }
};